package io.renren.modules.ccs.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.ccs.entity.RecordEntity;
import io.renren.modules.ccs.service.RecordService;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author SongR
 * @email 348329560@qq.com
 * @date 2018-07-25 16:03:25
 */
@RestController
@RequestMapping("ccs/record")
public class RecordController extends AbstractController{
    @Autowired
    private RecordService recordService;

    
    
    /**********************************************/
    /**********************************************/
    
    
    /**
     * 我的选题列表
     */
    @RequestMapping("/own/list")
    @RequiresPermissions("ccs:record:own:list")
    public R listOwn(@RequestParam Map<String, Object> params){
        PageUtils page = recordService.queryPageByOwn(params);
        return R.ok().put("page", page);
    }

    
    
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("ccs:record:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = recordService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{recordId}")
    @RequiresPermissions("ccs:record:info")
    public R info(@PathVariable("recordId") Long recordId){
    	RecordEntity record = recordService.queryInfo(recordId);
//        RecordEntity record = recordService.selectById(recordId);
        return R.ok().put("record", record);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("ccs:record:save")
    public R save(@RequestBody RecordEntity record){
        recordService.insert(record);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("ccs:record:update")
    public R update(@RequestBody RecordEntity record){
        ValidatorUtils.validateEntity(record);
        recordService.updateAllColumnById(record);//全部更新
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("ccs:record:delete")
    public R delete(@RequestBody Long[] recordIds){
        recordService.deleteBatchIds(Arrays.asList(recordIds));
        return R.ok();
    }

}
